//
//  KRSetBurglarizePointVC.m
//  KEREN
//
//  Created by MW on 2023/4/27.
//

#import "KRSetBurglarizePointVC.h"

@interface KRSetBurglarizePointVC ()
@property (nonatomic,strong)UITextField *textField;
@end

@implementation KRSetBurglarizePointVC


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavViewWithRightTitle:@"保存" navColorIswhite:YES withTitle:@"失窃地点"];

    WEAKSELF
    self.rightClickBlock = ^(void){
        [[NSNotificationCenter defaultCenter] postNotificationName:CHOOSEPOINT object:weakSelf.textField.text];
        [weakSelf.navigationController popViewControllerAnimated:YES];

        //User_update
    };
    [self setViewLayout];
}

- (void)setViewLayout{
    _textField = [UITextField setFlieldplaceholder:@"" Font:Font(16) borderColor:[UIColor clearColor]];
    _textField.layer.cornerRadius = 0;
    _textField.frame = CGRectMake(0, NAVTOP_Height, DEVICE_WIDTH, 60);
    [self.view addSubview:_textField];
    _textField.backgroundColor = Whire_Color;
    _textField.textColor = Color_333333;
    _textField.font = Font(15);
    if(_addr.length > 0){
        _textField.text = _addr;
    }else{
        _textField.placeholder = @"请输入失窃地点";
    }
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)
                                                name:@"UITextFieldTextDidChangeNotification"
                                              object:_textField];

    UIButton *clearBtn = [UIButton setButtonWithImage:@"clear" cornerRadius:0 backColor:[UIColor clearColor]];
    [self.view addSubview:clearBtn];
   // _textField.text = _userName;
    [clearBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-20);
        make.width.height.offset(21);
        make.centerY.equalTo(_textField);
    }];
    [UIView setLineViewWithframe:CGRectMake(24, 59, DEVICE_WIDTH - 48, 1) forinView:_textField];
    [clearBtn addTarget:self action:@selector(clear) forControlEvents:UIControlEventTouchUpInside];
}
- (void)clear{
    _textField.text = @"";
}

-(void)textFiledEditChanged:(NSNotification*)notification{
    UITextField *textField = notification.object;
    NSString *str = textField.text;
    if(str.length > 16 && textField.markedTextRange == nil){
        str =  [str substringToIndex:16];
        textField.text = str;
    }
}


@end
